import sys
import ConfigParser
from TileCache import Service
from TileCache.Client import seed

class Singleton(type):
    def __init__(cls, name, bases, dict):
        super(Singleton, cls).__init__(name, bases, dict)
        cls.instance = None
 
    def __call__(cls, *args, **kw):
        if cls.instance is None:
            cls.instance = super(Singleton, cls).__call__(*args, **kw)
 
        return cls.instance
 
class TileCacheFacade(object):
    __metaclass__ = Singleton    
    config = ConfigParser.ConfigParser()
    config.add_section("cache")
    config.add_section("basic")
    config.set("cache", "type", "Datastore")
    config.set("basic", "url", "http://labs.metacarta.com/wms/vmap0")
    config.set("basic", "type", "WMS")
    config.set("basic", "extension", "png") 
    service = Service.loadConfig(config)

    def seed(self, interval):
       sys.stderr.write("layers:%s\n" % self.service.layers)
       layer = self.service.layers["basic"]
       bboxlist=None
       padding = 0
       seed(self.service, layer, interval, bboxlist , padding, False, False)
    
    def dispatch(self, params):
        return self.service.dispatchRequest(params)